package com.disapand.dingdang.vo

import com.disapand.dingdang.common.ResponseEnum

/**
 * @author disapand
 * @date 2022/2/22 - 22:10 星期二
 */
data class ResponseVO(val success: Boolean, val errorCode: Number, val errorMessage: String?, val data: Any?) {

    constructor(errorCode: Number, errorMessage: String?, data: Any? = null):
            this(errorCode == 1000, errorCode, errorMessage, data)

    constructor(enum: ResponseEnum, data: Any? = null) :
            this(enum.errorCode == 1000, enum.errorCode, enum.errorMessage, data)

    companion object {
        fun ofSuccess(): ResponseVO {
            return ResponseVO(ResponseEnum.SUCCESS, null)
        }

        fun ofSuccess(data: Any?): ResponseVO {
            return ResponseVO(ResponseEnum.SUCCESS, data)
        }

        fun ofError(): ResponseVO {
            return ResponseVO(ResponseEnum.ERROR, null)
        }

        fun ofError(errorMessage: String): ResponseVO {
            return ResponseVO(9999, errorMessage)
        }

        fun ofError(enum: ResponseEnum, errorMessage: String): ResponseVO {
            return ResponseVO(enum.errorCode, errorMessage)
        }
    }
}
